#pragma once
#include "../CGIResource.h"
#include "CGIVulkanMemory.h"
#include "CGIVulkanDevice.h"
#include "CGIVulkanResource.h"
#include "CGIVulkanSwapChain.h"
#include "Runtime/Utils/SmartPtr.h"

namespace Alice{
    class CGIVulkanViewport;
    class CGICommandListImmediate;
    class CGIVulkanBackBuffer : public CGIVulkanTexture
    {
    public:
        CGIVulkanViewport* mViewport;
        CGIVulkanBackBuffer(CGIVulkanDevice& Device, CGIVulkanViewport* InViewport, EPixelFormat Format, uint32 SizeX, uint32 SizeY, ETextureCreateFlags UEFlags);
        void OnGetBackBufferImage(CGICommandListImmediate& inCGICmdList);
        void AcquireBackBufferImage(CGIVulkanCommandListContext& Context);
    };
    class CGIVulkanViewport : public CGIViewport {
    public:
        CGIVulkanDevice* mDevice;
        VkImage mImage;
        uint32 SizeX;
        uint32 SizeY;
        bool bIsFullscreen;
        EPixelFormat PixelFormat;
        int32 AcquiredImageIndex;
        CGIVulkanSwapChain* mSwapChain;
        void* WindowHandle;
        uint32 PresentCount;
        bool bRenderOffscreen;

        int8 LockToVsync;
        std::vector<CGIVulkanTexture*> mBackBufferImages;
        std::vector<CGIVulkanView*> mTextureViews;
        std::vector<VulkanSemaphore*> mRenderingDoneSemaphores;
        CGIVulkanBackBuffer* mCGIBackBuffer;
        VulkanSemaphore* AcquiredSemaphore;
        CGIVulkanViewport(CGIVulkanDevice* InDevice, void* InWindowHandle, uint32 InSizeX,uint32 InSizeY,bool bInIsFullscreen, EPixelFormat InPreferredPixelFormat);
        void CreateSwapChain(VulkanSwapChainRecreateInfo*inVulkanSwapChainRecreateInfo);
        SmartPtr<CGITexture> GetBackBuffer(CGICommandListImmediate& CGICmdList);
    };
}
